package com.example.qin.circle_view_dome;

import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.qin.circle_view_dome.view.CircleProgressBar;

public class MainActivity extends AppCompatActivity {
    private CircleProgressBar cpb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cpb = findViewById(R.id.cpb);
        /*模拟下载*/
        startDownload();
    }
    /**子线程下载*/
    private void startDownload() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i=0;i<=cpb.getMax();i++){
                    Message message = h.obtainMessage(123);
                    message.obj=i;
                    h.sendMessage(message);
                    SystemClock.sleep(50);
                }
            }
        }).start();
    }
    /**主线程更新UI*/
    private Handler h=new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what){
                case 123:
                 int progress= (int) msg.obj;
                 cpb.setProgress(progress);//自定义view里给构造器，在java里可在view本身点出
                break;
            }
            return false;
        }
    });
}
